<template>
  <el-dialog
    :title="title"
    :visible.sync="innerVisible"
    width="600px"
    @close="handleCancel"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="180px"
    >
      <el-form-item label="园区名称" prop="name">
        <el-input
          v-model="form.name"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="责任单位">
        <el-input
          v-model="form.unit"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="载体类型">
        <el-select
          placeholder="载体类型"
          v-model="form.type"
          clearable
          :disabled="isDetail"
        >
          <el-option
            v-for="item in carrierTypeOptions"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="园区建筑面积(平方米)">
        <el-input
          v-model="form.buildArea"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="园区可租面积(平方米)">
        <el-input
          v-model="form.rentArea"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="园区占地面积(亩)">
        <el-input
          v-model="form.landArea"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="停车位数量">
        <el-input
          v-model="form.parkCount"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="出租率">
        <el-input
          v-model="form.rentRate"
          placeholder="请输入"
          type="number"
          :min="1"
          :max="100"
          :disabled="isDetail"
        />
      </el-form-item>
    </el-form>

    <div
      slot="footer"
      class="dialog-footer"
      v-if="!isDetail"
    >
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { carrierTypeOptions } from '@/utils/project/data'
export default {
  name: 'ProgressDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '填写信息'
    },
    isDetail: {
      type: Boolean
    },
    currentData: {
      type: Object
    }
  },
  data() {
    return {
      form: {
        pkid: '',
        name: '',
        type: '',
        buildArea: '',
        rentArea: '',
        landArea: '',
        parkCount: '',
        rentRate: ''
      },
      rules: {
        name: [
          {
            required: true,
            message: '请输入园区名称',
            trigger: 'blur'
          }
        ]
      },
      innerVisible: false,
      yearList: ['2025', '2024']
    }
  },
  computed: {
    carrierTypeOptions() {
      return carrierTypeOptions
    }
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    },
    currentData(val) {
      this.form = val
    }
  },
  methods: {
    handleCancel() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.$emit('confirm', { ...this.form })
          this.handleCancel()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/dialog.scss';
::v-deep .el-input__inner {
  width: 280px !important;
}
</style>
